﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace KC.Business
{
	public static class Text
	{
		public static string StripHTML(string html)
		{
			return Regex.Replace(html.Trim(), @"<.*?>", "");
		}
		public static string BlogEncodeForStorage(string input)
		{
			if (string.IsNullOrEmpty(input)) return "";
			input = input
				.Trim()
				.Replace("[[", "<")
				.Replace("]]", ">")
				.Replace("\r\n", "<br />\r\n")
				.Replace("<a href=", "<a target=\"_blank\" href=");
			while (input.Contains("<br /><br /><br />"))
				input = input.Replace("<br /><br /><br />", "<br /><br />");
			return input.Trim();
		}
		public static string BlogDecodeForEditing(string input)
		{
			if (string.IsNullOrEmpty(input)) throw new ArgumentNullException("input");
			string output = input
				// Base formatting and replacements
				.Replace("<br />\r\n", "\r\n")
				.Replace("<", "[[")
				.Replace(">", "]]")
				.Trim();

			return output;
		}
	}
}
